package cn.iocoder.yudao.module.trade.order.vo;

import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.thirdparty.zxhx.dto.ZXHXOrderSubmitRespDTO;
import cn.iocoder.yudao.framework.validation.InEnumValue;
import cn.iocoder.yudao.module.api.dine.enums.DineStatusEnum;
import cn.iocoder.yudao.module.api.member.user.dto.MemberUserSimpleRespDTO;
import cn.iocoder.yudao.module.api.product.sku.dto.ProductPropertyValueRespDTO;
import cn.iocoder.yudao.module.api.promotion.groupon.dto.GrouponPackageRespDTO;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Schema(description = "管理后台 - 交易订单的分页项 Response VO")
@Data
public class TradeOrderPageItemRespVO extends TradeOrderBaseVO {

    @Schema(description = "订单状态名称", example = "待付款")
    private String statusName;

    @Schema(description = "售后状态：10-申请中、20-卖家通过、30-待卖家收货、40-等待平台退款、50-完成、61-买家取消售后、62-卖家拒绝、63-卖家拒绝收货", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
    private Integer afterSaleStatus;

    @Schema(description = "收件人地区名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "上海 上海市 普陀区")
    private String receiverAreaName;

    @Schema(description = "订单项列表", requiredMode = Schema.RequiredMode.REQUIRED)
    private List<Item> items;

    @Schema(description = "用户信息", requiredMode = Schema.RequiredMode.REQUIRED)
    private MemberUserSimpleRespDTO user;

    @Schema(description = "推广人信息")
    private MemberUserSimpleRespDTO brokerageUser;

    @Schema(description = "拼团记录编号，拼团订单才有值", example = "100")
    private Long combinationRecordId;

    @Schema(description = "拼团状态：0-进行中、1-拼团成功、2-拼团失败。拼团记录编号不为空时有效", example = "0")
    private Integer combinationStatus;

    @Schema(description = "秒杀活动编号，秒杀订单才有值", example = "100")
    private Long seckillActivityId;

    @Schema(description = "砍价活动编号，砍价订单才有值", example = "100")
    private Long bargainActivityId;

    @Schema(description = "砍价记录编号，砍价订单才有值", example = "100")
    private Long bargainRecordId;

    @Schema(description = "积分兑换活动的编号，积分兑换订单才有值", example = "100")
    private Long pointActivityId;

    @Schema(description = "点餐状态：0-无、10-待接单、20-备餐中、21-已拒单、22-已派单、30-已出餐、40-配送中、50-已送达", example = "1")
    @InEnumValue(DineStatusEnum.class)
    private Integer dineStatus;
    private String dineStatusName;

    @SuppressWarnings("unused")
    public String getDineStatusName() {
        if (dineStatusName == null) {
            return DineStatusEnum.getByValue(getDineStatus()).getName();
        }
        return dineStatusName;
    }

    @Schema(description = "接单时间，点餐下单时提供")
    private LocalDateTime acceptedTime;

    @Schema(description = "派单时间，点餐下单时提供")
    private LocalDateTime assignedTime;

    @Schema(description = "出餐时间，点餐下单时提供")
    private LocalDateTime packedTime;

    @Schema(description = "点餐餐桌编号，点餐订单才有值", example = "100")
    private Long dineDeskId;

    @Schema(description = "用餐人数，点餐订单才有值", example = "100")
    private Long dinePeoples;

    @Schema(description = "预定日期，预约下单才有值")
    private LocalDate reserveDate;

    @Schema(description = "预定时间段，如12:00-12:30，预约下单才有值")
    private String reservePeriod;

    @Schema(description = "团购套餐编号，团购订单才有值")
    private Long grouponPackageId;

    @Schema(description = "团购套餐，团购订单才有值")
    private GrouponPackageRespDTO grouponPackage;

    @Data
    public static class Item extends TradeOrderItemBaseVO {

        @Schema(description = "属性列表", requiredMode = Schema.RequiredMode.REQUIRED)
        private List<ProductPropertyValueRespDTO> properties;

    }

    @Schema(description = "供应方名称")
    private String supplyName;

    @Schema(description = "供应方关联单号")
    private List<String> supplyRelatedNos;

    @Schema(description = "供应方关联订单")
    @JsonIgnore
    private String supplyRelatedOrders;

    @Schema(description = "供应方关联订单")
    private List<ZXHXOrderSubmitRespDTO> supplyRelatedOrderList;

    @SuppressWarnings("unused")
    public List<ZXHXOrderSubmitRespDTO> getSupplyRelatedOrderList() {
        if (!JsonUtils.isJson(supplyRelatedOrders)) {
            return null;
        }
        return JsonUtils.parseArray(supplyRelatedOrders, ZXHXOrderSubmitRespDTO.class);
    }

}
